use std::collections::HashMap;
struct Solution;

impl Solution {
    pub fn can_construct(ransom_note: String, magazine: String) -> bool {
        let mut word_map = HashMap::new();
        for c in magazine.chars() {
            let count = word_map.entry(c).or_insert(0);
            * count += 1;
        }
        for c in ransom_note.chars() {
            match word_map.get_mut(&c) {
                None => {
                    return false;
                },
                Some(i) => {
                    if *i == 0 {
                        return false;
                    } else {
                        *i -= 1; 
                    }
                }
            }

        }
        return true;
        // let mut word_map = [0; 26];
        // for c in magazine.chars() {
        //     word_map[c as usize - 'a' as usize] += 1;
        // } 
        // dbg!(word_map);
        // for c in ransom_note.chars() {
        //     match word_map[c as usize - 'a' as usize] {
        //         0 => {
        //             return false;
        //         },
        //         _ => {
        //             word_map[c as usize - 'a' as usize] -= 1;
        //         }
        //     }
        // }
        // return true;
    }
}

fn main () {
    let ran = "aa".to_string();
    let mag = "aab".to_string();
    println!("{}", Solution::can_construct(ran, mag));
}